{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. 语句\n",
    "\n",
    "- [变量定义]\n",
    "  变量声明 (var const let)\n",
    "  类声明 (类声明,类表达式,抽象类)\n",
    "  函数声明 (函数声明 函数表达式)\n",
    "  生成器函数声明 (生成器函数声明 生成器函数表达式)\n",
    "  async 函数声明\n",
    "  async 生成器函数声明\n",
    "  装饰器语句\n",
    "  using 声明\n",
    "  枚举声明 enum\n",
    "\n",
    "- [typescript_类型定义]\n",
    "  类型别名 type\n",
    "  接口声明 interface\n",
    "\n",
    "- [分支语句]\n",
    "  if 语句\n",
    "  else 语句\n",
    "  switch 语句\n",
    "  case 子句\n",
    "  default 子句\n",
    "\n",
    "- [循环语句]\n",
    "  for 系列语句\n",
    "  while 语句\n",
    "  do...while 语句\n",
    "  continue 声明\n",
    "  break 语句\n",
    "  label 语句\n",
    "\n",
    "- [异常处理]\n",
    "  try 语句\n",
    "  catch 语句\n",
    "  finally 语句\n",
    "  throw 语句\n",
    "\n",
    "- [返回]\n",
    "  yield 表达式\n",
    "  return 语句\n",
    "\n",
    "- [esm]\n",
    "  export 语句\n",
    "  import 语句\n",
    "\n",
    "- [typescript-定义模块]\n",
    "  namespace 声明\n",
    "  module 声明\n",
    "\n",
    "- [其他]\n",
    "  表达式语句 (如 new )\n",
    "  块语句\n",
    "  debugger 语句\n",
    "  空语句\n",
    "  with 语句 (ts 中无法获得 正确的类型)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "ReferenceError: openFile is not defined\n",
       "    at <anonymous>:100:34"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "{\n",
    "    // - 1. 变量定义\n",
    "    // 变量声明(var let const)\n",
    "    var _a!: any;\n",
    "    let _l!: number;\n",
    "    const _c: string = \"_c\";\n",
    "\n",
    "    // 类声明 (类声明, 类表达式, 抽象类)\n",
    "    class _class { }\n",
    "    // 函数声明(函数声明 函数表达式)\n",
    "    function _function() {\n",
    "        return \"语句\"\n",
    "    }\n",
    "    // 生成器函数声明(生成器函数声明 生成器函数表达式)\n",
    "    function* _generator<T extends boolean>(): Generator<\"表达式\", \"\" | \"语句\", T> {\n",
    "        const _yieldReturn = yield \"表达式\" as const;\n",
    "        //       ^?\n",
    "        if (_yieldReturn) {\n",
    "            return \"语句\" as const\n",
    "        }\n",
    "        return \"\" as const\n",
    "    }\n",
    "    _generator().next(true);\n",
    "    // async函数声明\n",
    "    async function _asyncFunction() { }\n",
    "    // async生成器函数声明\n",
    "    async function* _asyncGenerator() { }\n",
    "\n",
    "    // 接口声明\n",
    "    interface _interface { }\n",
    "    // 类型别名声明\n",
    "    type _type = any;\n",
    "    // 枚举声明\n",
    "    enum _enum {\n",
    "        Blah = Math.random()\n",
    "    }\n",
    "    // using声明\n",
    "    try {\n",
    "        {\n",
    "            using file = await openFile();\n",
    "        } // `x[Symbol.dispose]()` is called\n",
    "    } catch { }\n",
    "    // 异步using\n",
    "    async function asyncUsing() {\n",
    "        await using x = new C();\n",
    "    } // `await x[Symbol.asyncDispose]()` is invoked\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "ReferenceError",
     "evalue": "a is not defined",
     "output_type": "error",
     "traceback": [
      "Stack trace:",
      "ReferenceError: a is not defined",
      "    at <anonymous>:4:3"
     ]
    }
   ],
   "source": [
    "{\n",
    "    // - 分支语句\n",
    "    // if语句\n",
    "    if (a > 1) {\n",
    "        // do something\n",
    "    }\n",
    "    // else语句\n",
    "    else if (a > 2) {\n",
    "        // do something\n",
    "    } else {\n",
    "        // do something\n",
    "    }\n",
    "    // switch语句\n",
    "    switch (a) {\n",
    "        // case子句\n",
    "        case 1:\n",
    "            // do something\n",
    "            break;\n",
    "        case 2:\n",
    "            // do something\n",
    "            break;\n",
    "        // default子句\n",
    "        default:\n",
    "            // do something\n",
    "            break;\n",
    "    }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    // 循环语句\n",
    "    // for系列语句\n",
    "    label: /* label语句 */ for (let i = 0; i < 2; i++) {\n",
    "        if (i == 0) {\n",
    "            // break语句\n",
    "            break label;\n",
    "        }\n",
    "        // continue声明\n",
    "        continue;\n",
    "    }\n",
    "    // while语句\n",
    "    while (false) { }\n",
    "    // do...while语句\n",
    "    do { } while (false);\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "Unknown error",
     "evalue": "[object Object]",
     "output_type": "error",
     "traceback": [
      "Stack trace:",
      "\"[object Object]\"",
      "    at <unknown>"
     ]
    }
   ],
   "source": [
    "{\n",
    "    // 异常处理\n",
    "    // try 语句\n",
    "    // catch 语句\n",
    "    // finally 语句\n",
    "    try { } catch { } finally { };\n",
    "    // throw 语句\n",
    "    throw {}\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "{\n",
    "    // - 其他\n",
    "    // 表达式语句(如 new )\n",
    "    /* declare */ class A {\n",
    "        constructor(){\n",
    "            this.x = 1;\n",
    "        };\n",
    "        x: number;\n",
    "    };\n",
    "    new A();\n",
    "    // 块语句\n",
    "    {\n",
    "        let x = 1;\n",
    "        let y = 2;\n",
    "        let z = x + y;\n",
    "    }\n",
    "    // debugger语句\n",
    "    // debugger;\n",
    "    // 空语句\n",
    "    const arr = [1, 2, 3];\n",
    "    for (let i = 0; i < arr.length; arr[i++] = 0);\n",
    "    // with语句(ts 中无法获得 正确的类型)\n",
    "    // @ts-expect-error\n",
    "    // with (Math) {\n",
    "    //     const E = PI;\n",
    "    // }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Deno",
   "language": "typescript",
   "name": "deno"
  },
  "language_info": {
   "codemirror_mode": "typescript",
   "file_extension": ".ts",
   "mimetype": "text/x.typescript",
   "name": "typescript",
   "nbconvert_exporter": "script",
   "pygments_lexer": "typescript",
   "version": "5.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
